import xxRequest, {xxLoginRequest} from "./service"
const cookie = wx.getStorageSync('cookies')
// 向微信请求 code
export function getloginCode() {
  return new Promise((resolve,reject)=>{
    wx.login({
      timeout: 1000,
      success:res=>{
        resolve(res.code)
      },
      fail:res=>{
        reject(res)
      }
    })
  })
}
// 服务器 将code 换取 token
export function codeToToken(code) {
  return xxLoginRequest.post("/login",{code})
}
// 确认token是否过期
export function checkToken(token) {
  return xxLoginRequest.post("/auth",{},{token})
}
// 确认session是否过期
export function checkSession() {
  return new Promise((resolve)=>{
    wx.checkSession({
      success: () => {
        resolve(true)
      },
      fail:()=>{
        resolve(false)
      }
    })
  })
}


// 发送验证码
export function getCaptchaSent(phone) {
  return xxRequest.post("/captcha/sent",{phone})
}
// 验证手机号和验证码
export function checkLoginCaptcha(phone,captcha) {
  return xxRequest.get("/login/cellphone",{phone,captcha})
}
// 通过手机号密码登录
export function getUserInfo(phone,password) {
  return xxRequest.get("/login/cellphone",{phone,password})
}
// 登录后 获取用户信息
export function getUserSubcount() {
  return xxRequest.get("/user/subcount",{ cookie})
}
// 游客登录
export function geteRegisterAnonimous(params) {
  return xxRequest.get("/register/anonimous")
}
// 退出登录
export function logoutAction() {
  return xxRequest.get("/logout",{cookie})
}
// 请求用户歌单
export function getUserSongList(uid="350638140") {
  return xxRequest.get("/user/playlist",{uid})
}